package com.kfy.observerdemo.Pub_Sub;

/**
 * @ProjectName: ObserverDemo
 * @Package: com.kfy.observerdemo.Pub_Sub
 * @Author: K.F.Y
 * @Date: 2021/5/8
 */
public class PersonSub implements ISubcriber{

    private String name;

    public PersonSub(String name) {
        this.name = name;
    }

    @Override
    public void subscribe(SubscribePublish subscribePublish) {
        System.out.println(name + " 订阅了 " + subscribePublish.getName());
        subscribePublish.attach(this);
    }

    @Override
    public void unsubscribe(SubscribePublish subscribePublish) {
        System.out.println(name + " 退订了 " + subscribePublish.getName());
        subscribePublish.detach(this);
    }

    @Override
    public void update(IPublisher publisher) {
        System.out.println(name + " 接收到 " + publisher.getName() + "的信息：" + publisher.getContent());
    }
}
